All Questions
12 questions
7votes
4answers
1kviews
LeetCode 977: Squares of a sorted array, maintaining non-decreasing order
I tried solving the LeetCode question like many others, trying to incorporate the O(n) time complexity requirement. Squares of a Sorted Array Given an integer array ...
5votes
3answers
891views
Counting swaps in a sequence sorting algorithm
I have been working on this question, https://open.kattis.com/problems/sequences. You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are n ‘?’s. ...
3votes
3answers
4kviews
New Year Chaos JavaScript, needs to be sped up
Similar to this question but this is for Python Original problem with description on hacker rank I am currently trying to iterate through a large number of arrays and count how many times numbers ...
6votes
3answers
43kviews
Minimum number of swaps required to sort the array in ascending order
Here is my problem statement. An excerpt: You are given an unordered array consisting of consecutive integers ∈ [1, 2, 3, ..., n] without any duplicates. You are ...
5votes
3answers
5kviews
Sort characters in a Python string by frequency
I wrote a solution to the leetcode problem Sort characters by frequency and the solution passes 34/35 test cases. On the last test case, there is a "time limit exceeded" error with an input string of ...
4votes
2answers
658views
Counting adjacent swaps to sort an array with 3 different values
This is the Kindergarten Excursion problem from kattis.com: The kindergarten teachers had finally managed to get all the kids in a line for the walk to the bus station and the weekly excursion. What ...
8votes
2answers
4kviews
HackerRank leaderboard challenge
I have been doing this challenge in which I need to determine and return one's (i.e. alice) rank on a leaderboard by comparing her scores to the others'. I made ...
3votes
1answer
3kviews
"Max Min" in HackerRank
I am trying to implement the solution for the problem "Max Min" in HackerRank. The solution runs for some test cases but for few test cases it pops out showing "Terminated due to Time Out" Problem: ...
3votes
1answer
690views
SPOJ GENERAL: sorting by swaps of distance k
I have been trying to solve this simple problem on SPOJ for quite some time now, but I keep on getting TLE (Time limit exceeded) for some reason. Since the problem is in Portuguese, a brief ...
3votes
3answers
389views
Sorting and eliminating duplicates
From Hacker Earth: Problem Statement: Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to give him ...
5votes
3answers
1kviews
Counting number of inversions
This is a HackerEarth Challenge Problem. Question: Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N friends, ...
3votes
3answers
418views
Speed up counting sort algorithm in Ruby
I'm attempting this simple HackerRank counting sort problem but testcase #3, which has 100,000 test cases, is timing out. Is there something particularly inefficient about this code? ...